#include <iostream>
int getrandomnum(float *p, int n);
float getaverage(float num[], int n);
void sort(float *num, int n);
void swap_val(float *a, float *b);
void swap_val(float &a, float &b)



int main()
{
    float *num = new float[10];

    getrandomnum(num, 10);

    std::cout << "平均温度为" << getaverage(num, 10) << std::endl;
    delete[] num;
    return 0;
}

int getrandomnum(float *p, int n)
{
    srand(time(0));
    for (int i = 0; i < 10; i++)
    {
        p[i] = (float)(rand() % 10000) / 100;
        std::cout << p[i] << " ";
    }
    return 0;
}

float getaverage(float *num, int n)
{
    int max = 0, min = 0;
    float sum = 0.0;

    for (int i = 0; i < n; i++)
    {
        sum += num[i];
        if (num[i] < num[min])
            min = num[i];
        if (num[i] > num[max])
            max = num[i];
    }
    sum -= num[min] + num[max];

    return sum / (n - 2);
}

void sort(float *num, int n)
{
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (num[i] > num[j])
            {
                //swap_val(&num[i], &num[j]);   //using pointers
                swap_val(num[i], num[j]);    //using references
            }
        }
    }
}

void swap_val(float *a, float *b)
{
    auto temp = *a;
    *a = *b;
    *b = temp;
}

void swap_val(float &ra, float &rb)
{
    auto temp = ra;
    ra = rb;
    rb = temp;
}